#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N=2e5+10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
int l,r;
void solve()
{
	cin>>l>>r;

	int t=(r+1)/2;

	if(t>=l) cout<<t-1<<'\n';
	else cout<<r-l<<'\n';


	
}

int main()
{
	close();
	int T; cin>>T;
	while (T--) solve();
	return 0;
}
//2a-1 mod a =a-1 //最大情况

//2a-1==r ->  a==(r+1/2)